package Convertisseur;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import jxl.Cell;

public class CompareWith_TableInfluencing extends VariableFlags{
	//protected ReceptionMeasure rm = new ReceptionMeasure();
	protected  ArrayList<Integer> N_Cordon_Influencing = new ArrayList<Integer>();
	
	
	
	public String getOP_Tool_Influencing(String OP_Influencing){
		return OP_Tool_Path.get(OP_Influencing);
	}
	
	//---------------------------------------------------------------------------
	// compare with table Influencing
	//---------------------------------------------------------------------------
	public void removeDuplicateWithOrder(List<Integer> list)   {
	      Set<Integer> setTemp  =   new  HashSet<Integer>();
	      List<Integer> listTemp  =   new  ArrayList<Integer>();
	   for  (Iterator<Integer> iter  =  list.iterator(); iter.hasNext();)   {
	         Object element  =  iter.next();
	         if  (setTemp.add((Integer) element))
	        	 listTemp.add((Integer) element);
	     } 
	     list.clear();
	     list.addAll(listTemp);
	     System.out.println( " remove duplicate "   +  list);
	 } 
	
	public void setCellNumberOfSheetInfluencing(){
		int numberRow = sheetInfluencing.getRows();
		for(int i=3; i<numberRow; i++){
			Cell cellRow [] = sheetInfluencing.getRow(i);
			
			int numberInfluencing = 0;
			for(int index=1; index<cellRow.length; index++){
				String cellContentRow = cellRow[index].getContents().toString();
				if(cellContentRow.contentEquals("1")|| cellContentRow.contentEquals("2")){
					numberInfluencing++;
					if((numberInfluencing>=2))
						N_Cordon_Influencing.add(i);
				}
				
			}
		}
		removeDuplicateWithOrder(N_Cordon_Influencing);
	}
	
	
	public String getValueOfInfluencing(String N_Cordon){
		int indexCellTable = 0;
		String value = "";
		Cell cell [] = sheetInfluencing.getColumn(0);
		int nbCell = cell.length;
		for(int i=2; i<nbCell; i++){
			String cellContent = "C"+cell[i].getContents().toString();
			if(cellContent.equals(N_Cordon)){
				indexCellTable = cell[i].getRow();
				for(String op: getOP_Influencing_Table(indexCellTable)){
					//value = value + "," +OP_Influencing_table_QDAS.get(op);
					value = value + "," +InitFor_QDAS_catalog.getOP_Influencing_table_QDAS().get(op);
					
					String tool = getOP_Tool_Influencing(op);
					
					
					
					if(tool.equals("1")){
						//value = value+" "+OP_Tool_table_QDAS.get(op)[0];}
						value = value+" "+InitFor_QDAS_catalog.getOP_Tool_table_QDAS().get(op)[0];}
					if(tool.equals("2")){
						//value = value+" "+OP_Tool_table_QDAS.get(op)[1];}
						value = value+" "+InitFor_QDAS_catalog.getOP_Tool_table_QDAS().get(op)[1];}
					if(tool.equals("3")){
						value = value+" "+InitFor_QDAS_catalog.getOP_Tool_table_QDAS().get(op)[2];}
					if(tool.equals("4")){
						value = value+" "+InitFor_QDAS_catalog.getOP_Tool_table_QDAS().get(op)[3];}
				}
			}
		}
		if(!value.equals("")){value = value.substring(1);}
		
		return value;
	}
	
	public String getOP_Princial_Table(int indexCell_Number){
		String cellContent_OP_XX = "";
		Cell cell [] = sheetInfluencing.getRow(indexCell_Number);
		int nbCell = cell.length;
		for(int i=1;i<nbCell; i++){
			String cellContent = cell[i].getContents().toString();
			if(cellContent.contentEquals("1")){
				int column = cell[i].getColumn();
				cellContent_OP_XX = sheetInfluencing.getCell(column,0).getContents().toString();
				cellContent_OP_XX = cellContent_OP_XX.toUpperCase();
			}
		}

		return cellContent_OP_XX;
	}
	public  ArrayList<String> getOP_Influencing_Table(int indexCell_Number){
		ArrayList<String> Contents_OP_XX_Influencing = new ArrayList<String>(); 
		Cell cell [] = sheetInfluencing.getRow(indexCell_Number);
		int nbCell = cell.length;
		for(int i=1;i<nbCell; i++){
			String cellContent = cell[i].getContents().toString();
			if(cellContent.contentEquals("2")){
				int column = cell[i].getColumn();
				String cellContent_OP_XX = sheetInfluencing.getCell(column,0).getContents().toString();
				cellContent_OP_XX = cellContent_OP_XX.toUpperCase();
				Contents_OP_XX_Influencing.add(cellContent_OP_XX);
			}
		}
		return Contents_OP_XX_Influencing;
	}
	//---------------------------------------------------------------------------
	// fin compare with table Influencing
	//---------------------------------------------------------------------------

}
